package com.hljx.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.hljx.config.Result;
import com.hljx.dto.DateDTO;
import com.hljx.dto.SysDictPageDTO;
import com.hljx.entity.EtlItemImport;
import com.hljx.service.EtlItemImportService;
import io.swagger.v3.oas.annotations.Operation;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.util.List;

/**
 * <p>
 * 数据抽取初步计算表 前端控制器
 * </p>
 *
 * @author ${author}
 * @since 2023-11-30
 */
@RestController
@RequestMapping("/etlItemImport")
public class EtlItemImportController {
    @Autowired
    private EtlItemImportService  etlItemImportService;

    @Operation(summary = "导出和下载模板")
    @PostMapping("/export")
    public void export( HttpServletResponse response) throws ClassNotFoundException {
        etlItemImportService.export(response);
    }

    @Operation(summary = "导入")
    @PostMapping("/importExcel")
    public void importExcel(@RequestParam("file") MultipartFile file, HttpServletResponse response) throws ClassNotFoundException, IOException {
        etlItemImportService.importExcel(file,response);
    }


    @Operation(summary = "修改")
    @PostMapping("/update")
    public Result update(@RequestBody  EtlItemImport  etlItemImport)  {
        boolean b = etlItemImportService.updateById(etlItemImport);
        return   Result.success(true);
    }




    @Operation(summary = "删除")
    @PostMapping("/remove")
    public Result remove(@RequestParam List ids)  {
        boolean b = etlItemImportService.removeBatchByIds(ids);
        return   Result.success(true);
    }


    @Operation(summary = "分页查询")
    @PostMapping("/pageByPeriod")
    public Result< IPage<EtlItemImport> > pageByPeriod(@RequestBody DateDTO  dateDTO)  {
        IPage<EtlItemImport> etlItemImport = etlItemImportService.pageByPeriod(dateDTO);
        return   Result.success(etlItemImport);
    }




}
